<template>
  <div>
    <!-- 表格 -->
    <subTable
      :table-label="tableLabel"
      :table-data="listFilter.slice((currentpage-1)*pagesize,currentpage*pagesize)"
    >
      <el-table-column slot="button" :min-width="2" label="操作" prop="manage" align="center">
        <template slot-scope="scope">
          <el-dropdown trigger="click" @command="handleCommand($event,scope.row)">
            <el-button type="primary">
              选择
            </el-button>
          </el-dropdown>
        </template>
      </el-table-column>
    </subTable>
    <!-- 分页组件 -->
    <pagination
      :total="total"
      :current-page="currentpage"
      :page-size="pagesize"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange"
    />
  </div>
</template>

<script>
import SubTable from '@/components/Eltable'
import Pagination from '@/components/Pagination' // 分页组件
import { getMemberList } from '@/api/operate/promcode.js' // 数据接口
export default {
  components: {
    Pagination,
    SubTable
  },
  data() {
    return {
      total: 0,
      currentpage: 1,
      pagesize: 20,
      tableLabel: [
        {
          label: '编号', width: '1', prop: 'id'
        }, {
          label: '名称', width: '4', prop: 'memberName'
        }
      ],
      tableData: [],
      listFilter: []
    }
  },
  mounted() {
    this.getMemberList()
  },
  methods: {
    handleSizeChange(val) {
      console.log(val)
      this.currentpage = 1
      this.pagesize = val.value
      if (this.pagesize >= 20) {
        scrollTo(50, 800)
      }
    },
    handleCurrentChange(val) {
      console.log(val)
      this.currentpage = val.value
      if (this.pagesize >= 20) {
        scrollTo(50, 800)
      }
    },
    handleFilter() {
      this.listFilter = this.tableData.filter(item => {
        return true
      })
      this.total = this.listFilter.length
    },
    getMemberList() {
      getMemberList().then(response => {
        this.tableData = response.data.items
        this.total = response.data.items.length
        this.listFilter = response.data.items
      })
    }
  }
}
</script>

<style scoped>

</style>
